package com.burgeon.backend.SHOPBACKEND.rest;

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

/*云仓订单发货单,根据提交状态为1 ，没有快递公司的信息*/
public class QuerryMailFee extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public QuerryMailFee(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }


    /**
     * 发送并接收字符创
     * @return
     */

    public String getData(String phone) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(phone), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception(str);
        }

        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");




        return jsonArray.getJSONArray(0).getString(0);
    }

    private MultiValueMap Data(String phone) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段


        columns.add("'C_VIPTYPE_ID;INTEGRAL'");//积分抵扣运费需要积分

        params.put("columns", columns);
        params.put("table", "C_VIP");//表名



        HashMap paramss = new HashMap();//DOCNO  (AK)	单据编号ISACTIVE
        HashMap expr1 = new HashMap();

        expr1.put("column", "'C_VIPTYPE_ID;ISACTIVE'");//积分抵扣运费需要积分
        expr1.put("condition", "Y");

        HashMap expr2 = new HashMap();
        String ac = phone;
        expr2.put("column","CARDNO");
        expr2.put("condition",ac);

        paramss.put("combine", "and");//关系
        paramss.put("expr1",expr1);
        paramss.put("expr2",expr2);

        params.put("params", paramss);
        System.err.println(params);

        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        QuerryMailFee querryYCRetailout = new QuerryMailFee("39.99.239.133:55321", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(querryYCRetailout.getData("17732141036"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
